package com.erik.lin.test.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by Erik on 2017/5/24.
 */
public class MysqlCon {
    static Connection con;//Declare a Connection object
    static String driver = "com.mysql.jdbc.Driver";// the MySQL driver
    static String url = "jdbc:mysql://10.20.52.249:3306/md?useUnicode=true&amp;characterEncoding=UTF-8";// URL points to destination database to manipulate
    static String user = "root";//user name for the specified database
    static String pwd = "root";//the corresponding password

    public static Connection getConnection() {
        try {
            Class.forName(driver);// add MySQL driver
            System.out.println("Database driver is successfully added");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            con = DriverManager.getConnection(url, user, pwd);//create a connection object
            System.out.println("Database connection is successful");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return con;
    }
}
